import React, { Component } from 'react'
import { Table,Button} from 'antd';
import {getCarLIstApi} from '../../apis/carApi';

export default class CarsList extends Component {

    state={
        list:[],
        total:0,
        pageSize:2,
        pageNumber:1,
    }
    componentDidMount(){
        this.getCarList()
    };

    getCarList=async (params)=>{
        try {
            const data=await getCarLIstApi(params);
            const date=data.filter((item)=>item.status != "下架");
            this.setState({list:date})
            // console.log(data);
        } catch (error) {
            console.log('error',error);
        }
    }
    goToInform=(id)=>{
        this.props.history.push({pathname:'/main/checkCar',state:{id}})
    }
    
    render() {
        const columns = [
            {
            title: '车辆图片',
            dataIndex: 'carImg',
            render:(item)=>{
                return  <img src={"http://localhost:3008/images/"+item} alt="" style={{width:120}} />
                }
            },
            {
            title: '车主',
            render:(item)=>{
            return  <span>{item.ownerId.name}</span>
            }
            },
            {
            title: '车辆品牌',
            dataIndex: 'brand',
            },
            {
            title: '价格/天',
            dataIndex: 'price',
            },
            {
            title: '详细信息',
            render:(item)=>{
                return  <Button onClick={()=>this.goToInform(item._id)} type="primary">详情</Button>
            }
            },
        ];
        const {list,total,pageSize} = this.state;
        const  page={
            total,
            pageSize,
            // onChange:this.onChange
        }

        return (
            <div>
                <Table rowKey="_id" columns={columns} dataSource={list} pagination={page} />
            </div>
        )
    }
}
